<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>修改用户</title>
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
    <script src="../../../backstage/js/jquery.min.js"></script>
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
</head>

<body>
<div class="y-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="username" required="" lay-verify="username"  autocomplete="off" class="layui-input"disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="state" class="layui-form-label">
                <span class="x-red">*</span>用户状态
            </label>
            <div class="layui-input-inline">
                <input type="text" id="state" name="state" value="" required="" lay-verify="state"  autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class='x-red'>*</span>修改状态
            </label>
            <div class="layui-input-block">
                <select name="article_category_id" id="newstate">
                    <option value="">请选择操作</option>
                    <option value="0">注销用户</option>
                    <option value="1">冻结用户</option>
                    <option value="2">恢复账户</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="edit" class="layui-form-label"> </label>
            <input id="edit" type="button" class="layui-btn" lay-filter="edit" lay-submit="edit" value="确认修改"> </input>
        </div>
    </form>
</div>

<script>
layui.use(['form', 'layer'], function() {
    $ = layui.jquery;
    var form = layui.form(),
        layer = layui.layer;

    //自定义验证规则
    form.verify({
        username: function(value) {
            if (value.length <= 0) {
                return '用户名不为空';
            }
        }
    });
    $(document).ready(function() {
        //获取传递过来的localStorage
        var id = window.localStorage.getItem('msg');
        console.log(id);
        $.ajax({
            type: 'POST',
            url: '/userManager/selectById',
            dataType: "json",
            data: {uid: id},
            error: function () {
                console.log("失败");
            },
            success: function (result) {
                $("#username").val(result.username);
                $("#state").val(result.state);

                console.log(result);
                //修改
                $("#edit").click(function () {

                    var username = $("#username").val();

                    var temp = $("#newstate").val();

                    console.log(username);

                    $.ajax({
                        type: 'POST',
                        url: '/userManager/changeState',
                        dataType: "json",
                        data: {username: username, temp: temp},
                        error: function () {
                            alert("失败");
                        },
                        success: function (data) {
                            if (data.msg == "更新成功") {
                                alert("更新成功");
                            } else if (data.msg == "更新失败") {
                                alert("用户不存在！")
                            } else if (data.msg == "uid或temp不能为空！") {
                                alert("uid或temp不能为空！")
                            }
                            location.reload();
                        }
                    });
                });
            }
        });
    });

});
</script>
</body>

</html>